//
//  AppDelegate.m
//  Distributor
//
//  Created by 主事丫环 on 2019/5/5.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "AppDelegate.h"

#import "TabBarViewController.h"//tabbar
#import "BShopNoIncomeVC.h"//B级经销商 无收益

#import <AMapLocationKit/AMapLocationKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>

#import <WXApi.h>
#import <AlipaySDK/AlipaySDK.h>

#import <UserNotifications/UserNotifications.h>
#import <AVFoundation/AVFoundation.h>

//分享
#import "JSHAREService.h"
//推送
#import "JPUSHService.h"
#import <AdSupport/AdSupport.h>//idfa功能头文件(可选)

#import "ZNewPartOnAlertView.h"//配件/整机上架提示

static NSString * const jpushAppKey = @"3eb8fce22a3b002ddaed34b8";
static NSString * const channel = @"";
static BOOL isProduction = FALSE;
static NSString *APIKey = @"8e9b837459ad649638a8d9366beeb521";

@interface AppDelegate ()<JPUSHRegisterDelegate,JPUSHGeofenceDelegate,AVAudioPlayerDelegate,UNUserNotificationCenterDelegate,WXApiDelegate>

@property (nonatomic, retain)AVAudioPlayer *player;
@property(nonatomic,strong)UIView *bgView;

@end

@implementation AppDelegate

#pragma mark - 应用程序启动后，要执行的委托调用，系统启动代理(第一个页面的加载)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //状态栏字体
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    [[UIApplication sharedApplication] registerForRemoteNotifications];//开启远程推送
    
    //微信
    [WXApi registerApp:@"wxc0faecc37e5f61a2"];
    
    //地图
    [AMapServices sharedServices].apiKey = APIKey;
    
    //极光推送
    [self jPushConfigWithOptions:launchOptions];
    
    //分享设置
    [self jShareConfig];
    
    //主界面创建
    [self setupRootWindow];
    
    [self shwoBgview];
    
    [self appNotActivityWith:launchOptions];
    
    return YES;
}

#pragma mark - 打开别的APP(支付分享等)
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
    // 其他如支付等SDK的回调
    KMyLog(@"fsasasfa%@",url.host);
    if ([url.host isEqualToString:@"safepay"]) {
        [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
            //code：拿到授权信息，完成业务逻辑
            KMyLog(@"resultDic%@",resultDic);
            if ([[resultDic objectForKey:@"resultStatus"] integerValue] == 9000) {
                [Center postNotificationName:@"shouquanSuccess" object:nil userInfo:resultDic];
            }
        }];
        //跳转支付宝钱包进行支付，处理支付结果
               [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
                   
                   NSString *statues = resultDic[@"resultStatus"];
                   if ([statues isEqualToString:@"9000"]) {
                       //支付成功后通知后台
                       [Center postNotificationName:@"PaySuccess" object:nil];
                       
                   }else {
                       [Center postNotificationName:@"PayFail" object:nil];
                   }
               }];
    }else{
        return [WXApi handleOpenURL:url delegate:self];
    }
    return YES;
}
#pragma mark - 微信授权登录 微信支付
-(void)onResp:(BaseResp*)resp {
    if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
        // strTitle = [NSString stringWithFormat:@"发送媒体消息结果"];
    }
    
    if ([resp isKindOfClass:[SendAuthResp class]]) {   //授权登录的类。
        SendAuthResp *aresp = (SendAuthResp *)resp;
        NSDictionary *diccc = @{@"code":aresp.code};
        [Center postNotificationName:@"wechatshouquanSuccess" object:nil userInfo:diccc];
    }
    
    if ([resp isKindOfClass:[PayResp class]]) {
        // strTitle = [NSString stringWithFormat:@"支付结果"];
        // NSLog(@"%@",PayResp.returnKey);
        switch (resp.errCode) {
            case WXSuccess: {
                NSLog(@"支付结果: 成功!");
                [Center postNotificationName:@"PaySuccess" object:nil];
            }
                break;
            case WXErrCodeCommon: {
                //签名错误、未注册APPID、项目设置APPID不正确、注册的APPID与设置的不匹配、其他异常等
                NSLog(@"支付结果: 失败!");
            }
                break;
            case WXErrCodeUserCancel: {
                //用户点击取消并返回
                NSLog(@"用户点击取消并返回");
                [Center postNotificationName:@"PayFail" object:nil];
            }
                break;
            case WXErrCodeSentFail: {
                //发送失败
                NSLog(@"发送失败");
            }
                break;
            case WXErrCodeUnsupport: {
                //微信不支持
                NSLog(@"微信不支持");
            }
                break;
            case WXErrCodeAuthDeny: {
                //授权失败
                NSLog(@"授权失败");
            }
                break;
            default:
                break;
        }
    }
}
#pragma mark - 应用程序将要由活动状态切换到非活动状态时执行的委托调用，如按下home 按钮，返回主屏幕，或全屏之间切换应用程序等
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

#pragma mark - 在应用程序已进入后台程序时，要执行的委托调用。所以要设置后台继续运行，则在这个函数里面设置即可
- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    //APP角标设置为0
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

#pragma mark - 在应用程序将要进入前台时(被激活)，要执行的委托调用，与applicationWillResignActive方法相对应
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    [application setApplicationIconBadgeNumber:0];
    //[application cancelAllLocalNotifications];
}

#pragma mark - 在应用程序已被激活后，要执行的委托调用，刚好与  applicationDidEnterBackground 方法相对应
- (void)applicationDidBecomeActive:(UIApplication *)application {
    //市县级 未缴费
    if (AGENT_LEVEL !=1)
    {
        [self requestcountmy];
    }
}
//市县级 是否缴费查询
-(void)requestcountmy{
    
    [NetWorkTool POST:CcentenInfo param:nil success:^(id dic) {
        NSString *string = [[dic objectForKey:@"data"] objectForKey:@"is_power"];
        
        if (string.length>0  && [string integerValue]== 0 ) {
            [USER_DEFAULT setObject:string forKey:@"is_power"];
        }
        else if (string.length>0 && [string integerValue]== 1 ) {
            [USER_DEFAULT setObject:string forKey:@"is_power"];
        }
        
    } other:^(id dic) {
        
    } fail:^(NSError *error) {
        
    } needUser:YES];
}
#pragma mark - 在应用程序要完全退出的时候，要执行的委托调用
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark - APNS注册成功 获取设备deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    //上传devieceToken到极光
    [JPUSHService registerDeviceToken:deviceToken];
    KMyLog(@"登录的user_id:%@",KUID);
    //JPush 监听登陆成功
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkDidLogin:) name:kJPFNetworkDidLoginNotification object:nil];
}

#pragma mark - APNs注册失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    NSLog(@"注册APNs失败");
}

#pragma mark - iOS3.0-iOS10收到远程推送
//如果 App 状态为正在前台或者点击通知栏的通知消息，那么此函数将被调用，并且可通过 AppDelegate 的 applicationState 是否为 UIApplicationStateActive 判断程序是否在前台运行。此种情况在此函数中处理
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    [JPUSHService handleRemoteNotification:userInfo];
}

#pragma mark - iOS7.0以上收到远程推送 - 我们在此处做远程推送处理就可以了
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    completionHandler(UIBackgroundFetchResultNewData);
    NSLog(@"获取的信息:%@",userInfo);
    
    [JPUSHService handleRemoteNotification:userInfo];
    
    NSDictionary *diccc = @{@"textstr":@""};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:APPDELEGATE_REQUEST_REFRESHLISTDATA object:nil userInfo:diccc];
    
    if ([[userInfo allKeys] containsObject:@"complaintId"]) {
        //旗下师傅的投诉
        NSString *sterename = @"shouhouweiixui";
        NSString *filePath = [[NSBundle mainBundle] pathForResource:sterename ofType:@"m4a"];
        NSURL *fileUrl = [NSURL URLWithString:filePath];
        SystemSoundID soundID = 0;
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);
        AudioServicesAddSystemSoundCompletion(soundID,NULL,NULL,soundCompleteCallBack,NULL);
        AudioServicesPlaySystemSound(soundID);
        
        [[UIApplication sharedApplication].keyWindow addSubview: self.bgView];
    } else if ([[userInfo allKeys] containsObject:@"newParts"]){
        //1配件或2整机上架通知
        NSString *newPartStr = [userInfo objectForKeyNotNil:@"newParts"];
        ZNewPartOnAlertView *view = [[ZNewPartOnAlertView alloc] init];
        view.alertType = newPartStr;
        [view showView];
    } else if ([[userInfo allKeys] containsObject:@"timeoutOrder"]){
        //您有超时订单未处理
        NSString *sterename = @"ninyouchaoshidingdanweichuli";
        NSString *filePath = [[NSBundle mainBundle] pathForResource:sterename ofType:@"m4a"];
        NSURL *fileUrl = [NSURL URLWithString:filePath];
        SystemSoundID soundID = 1;
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);
        AudioServicesAddSystemSoundCompletion(soundID,NULL,NULL,soundCompleteCallBack,NULL);
        AudioServicesPlaySystemSound(soundID);
    }
    
}

#pragma mark - iOS4-iOS10接收本地通知
//(如果App在前台无论点不点击通知，都会触发该方法，如果是在后台，只有点击通知才触发该方法)
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
    NSLog(@"收到本地通知");
}

#pragma mark - iOS 10新增的两个方法
//App在前台获取到通知会走该方法
//只有当应用程序位于前台时，该方法才会在委托上调用。如果方法未被执行或处理程序没有及时调用，则通知将不会被提交。
//应用程序可以选择将通知呈现为 声音、徽章、警报、或通知列表中。此决定应基于通知中的信息是否对用户可见。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
    completionHandler(UNNotificationPresentationOptionAlert);
}

//只有点击通知进入App时触发，在该方法内统计有效用户点击数（无论前台还是后台）
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
    completionHandler();
}

//当从应用外部通知界面或通知设置界面进入应用时，该方法将回调
- (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)){
}

//在 2.1.9 版本及以上可实现 SDK 封装的 JPUSHRegisterDelegate 协议方法，适配 iOS10 新增的 delegate 协议方法
/*
 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler;
 // NSDictionary * userInfo = notification.request.content.userInfo;
 // APNs 内容为 userInfo
 */
/*
 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler;
 // NSDictionary * userInfo = response.notification.request.content.userInfo;
 // APNs 内容为 userInfo
 */
/*
 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification;
 */
#pragma mark - ******------程序配置处理------******
#pragma mark - ******创建主界面******
- (void)setupRootWindow{
    NSString *set = [USER_DEFAULT objectForKey:@"level"];
    if (KTOKEN == nil || [KTOKEN isEqualToString:@""]) {
        //登录界面
        DISLoginViewController *vc = [[DISLoginViewController alloc]init];
        BaseNavViewController *nav = [[BaseNavViewController alloc]initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        self.window.rootViewController = nav;
    } else if ([set integerValue] == 3){
        //B级经销商 无收益(暂时不考虑)
        //BShopNoIncomeVC *vc = [BShopNoIncomeVC new];
        //BaseNavViewController *nav = [[BaseNavViewController alloc] initWithRootViewController:vc];
        //self.window.rootViewController = nav;
    } else {
        //创建Tabbar
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        TabBarViewController *tabbar = [[TabBarViewController alloc]init];
        self.window.rootViewController = tabbar;
    }
    
    //存储udid
    NSString *udid =[USER_DEFAULT objectForKey:@"udid"];
    if (strIsEmpty(udid)) {
        udid =    [self uuid];
        [USER_DEFAULT setObject:udid forKey:@"udid"];
    }
}

#pragma mark - ******极光推送******
- (void)jPushConfigWithOptions:(NSDictionary *)launchOptions{
    // 3.0.0及以后版本注册
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    if (@available(iOS 12.0, *)) {
        entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
    } else {
        entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
    }
    
    //注册通知
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    
    //如果使用地理围栏功能，需要注册地理围栏代理
    [JPUSHService registerLbsGeofenceDelegate:self withLaunchOptions:launchOptions];
    
    //如不需要使用IDFA，advertisingIdentifier 可为nil
    [JPUSHService setupWithOption:launchOptions appKey:jpushAppKey
                          channel:channel
                 apsForProduction:isProduction
            advertisingIdentifier:nil];
    
    //2.1.9版本新增获取registration id block接口。
    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
        if(resCode == 0){
            NSLog(@"registrationID获取成功：%@",registrationID);
        }else{
            NSLog(@"registrationID获取失败，code：%d",resCode);
        }
    }];
    
    //APP角标设置为0
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    
    if([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0){//8.0以后使用这种方法来注册推送通知
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    } else {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    }
    
    if (@available(iOS 10.0, *)) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        }];
        center.delegate = self;
    }
    
    //收到消息(非APNs) 的通知监听(自定义消息)(极光的应用内消息)
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(jPushDidReceiveNotificationMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
}

//极光推送登录成功后调用的方法
- (void)networkDidLogin:(NSNotification *)notification {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:kJPFNetworkDidLoginNotification
                                                  object:nil];
    NSString *str  = [NSString stringWithFormat:@"%@",[JPUSHService registrationID]];
    KMyLog(@"JPush标识此设备的 registrationID:%@",str);
}

#pragma mark - 收到极光的应用内推送消息处理(非APNs消息)
- (void)jPushDidReceiveNotificationMessage:(NSNotification *)notification {
    //收到的是自定义消息，只有在前端运行的时候才能收到
    NSDictionary * userInfo = [notification userInfo];
    NSLog(@"收到的推送消息:%@",userInfo);
//    NSString *content = [userInfo valueForKey:@"content"];
//    NSString *messageID = [userInfo valueForKey:@"_j_msgid"];
//    NSDictionary *extras = [userInfo valueForKey:@"extras"];
//    NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //服务端传递的 Extras 附加字段，key 是自己定义的
}

#pragma mark - JPUSHRegisterDelegate - 推送注册代理
//iOS10特性 APP在前台获取通知
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
    //选择是否提醒用户 Badge Sound Alert三种类型
    completionHandler(UNNotificationPresentationOptionAlert);
    
    NSDictionary *userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]){
        [JPUSHService handleRemoteNotification:userInfo];
    }
}

//iOS10特性 点击通知进入APP
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
    completionHandler();//系统要求执行这个方法
    
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
}

//iOS10特性
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)){
    if (notification && [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //从通知界面直接进入应用
    }else{
        //从通知设置界面进入应用
    }
}
#pragma mark - JPUSHGeofenceDelegate - 推送地理围栏代理
//进入地理围栏区域
- (void)jpushGeofenceIdentifer:(NSString * _Nonnull)geofenceId didEnterRegion:(NSDictionary * _Nullable)userInfo error:(NSError * _Nullable)error{
    
}

//离开地理围栏区域
- (void)jpushGeofenceIdentifer:(NSString * _Nonnull)geofenceId didExitRegion:(NSDictionary * _Nullable)userInfo error:(NSError * _Nullable)error{
    
}
#pragma mark - iOS设备收到一条APNs的处理
//App状态为未运行
- (void)appNotActivityWith:(NSDictionary *)launchOptions{
    //APNs内容获取(APP未运行)
    NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
    KMyLog(@"APP未运行收到的通知内容%@",remoteNotification);
    if (remoteNotification) {
        KMyLog(@"用户点击APNs通知导致APP被启动");
    }else{
        KMyLog(@"用户其他行为启动APP");
    }
}

#pragma mark - ******极光分享******
- (void)jShareConfig{
    //设置应用标识
    JSHARELaunchConfig *config = [[JSHARELaunchConfig alloc] init];
    config.appKey = @"3eb8fce22a3b002ddaed34b8";
    config.SinaWeiboAppKey = @"374535501";
    config.SinaWeiboAppSecret = @"baccd12c166f1df96736b51ffbf600a2";
    config.SinaRedirectUri = @"https://www.jiguang.cn";
    config.QQAppId = @"1105864531";
    config.QQAppKey = @"glFYjkHQGSOCJHMC";
    config.WeChatAppId = @"wxc0faecc37e5f61a2";
    config.WeChatAppSecret = @"389e6b7d8f50cb9412b7a6ce0f3b42b0";
    config.FacebookAppID = @"1847959632183996";
    config.FacebookDisplayName = @"JShareDemo";
    config.TwitterConsumerKey = @"4hCeIip1cpTk9oPYeCbYKhVWi";
    config.TwitterConsumerSecret = @"DuIontT8KPSmO2Y1oAvby7tpbWHJimuakpbiAUHEKncbffekmC";
    config.JChatProAuth = @"a7e2ce002d1a071a6ca9f37d";
    
    [JSHAREService setupWithConfig:config];
    [JSHAREService setDebug:YES];
}
#pragma mark - 其他的操作
/**
 弹出框的背景图
 */
-(void)shwoBgview{
    self.bgView = [[UIView alloc]init];
    self.bgView.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT);
    
    self.bgView.backgroundColor = RGBA(1, 1, 1, 0.5);
    UIView *whiteBGView = [[UIView alloc]init];
    whiteBGView.backgroundColor = [UIColor whiteColor];
    whiteBGView.layer.masksToBounds = YES;
    whiteBGView.layer.cornerRadius = 6;
    [self.bgView addSubview:whiteBGView];
    [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.height.offset(240);
        make.left.offset(22);
        make.right.offset(-22);
    }];
    
    UIImageView *upImage = [[UIImageView alloc]initWithFrame:CGRectMake(KWIDTH/2-22-20, 20, 40, 40)];
    upImage.layer.masksToBounds = YES;
    upImage.layer.cornerRadius = 20;
    [whiteBGView addSubview:upImage];
    upImage.image = [UIImage imageNamed:@"组732"];
    
    UILabel *UpLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 72, KWIDTH-44, 21)];
    [whiteBGView addSubview:UpLable];
    UpLable.font = FontSize(16);
    UpLable.textColor = [UIColor colorWithHexString:@"#333333"];
    UpLable.textAlignment =  NSTextAlignmentCenter;
    UpLable.text = @"您有一条投诉信息";
    UILabel *DowLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 103, KWIDTH-44, 21)];
    [whiteBGView addSubview:DowLable];
    
    DowLable.font = FontSize(14);
    DowLable.textColor = [UIColor colorWithHexString:@"#333333"];
    DowLable.textAlignment =  NSTextAlignmentCenter;
    //    DowLable.text = @"请准时上门处理！";
    
    UIButton *iKnowBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [iKnowBut setTitle:@"我知道了" forState:(UIControlStateNormal)];
    [iKnowBut setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [iKnowBut setBackgroundColor:[UIColor colorWithHexString:@"#70BE68"]];
    iKnowBut.layer.masksToBounds = YES;
    iKnowBut.layer.cornerRadius = 4;
    [iKnowBut addTarget:self action:@selector(ikenowAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteBGView addSubview:iKnowBut];
    [iKnowBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(48);
        make.left.offset(28);
        make.right.offset(-28);
        make.bottom.offset(-39);
    }];
}

- (void)ikenowAction:(UIButton *)but{
    [self.bgView removeFromSuperview];
}

//获得UUID
- (NSString*)uuid {
    CFUUIDRef puuid = CFUUIDCreate( nil );
    CFStringRef uuidString = CFUUIDCreateString(nil, puuid);
    NSString *result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString));
    return result;
}
void soundCompleteCallBack(SystemSoundID soundID, void *clientData){
    NSLog(@"播放完成");
}
@end
